package com.onlyxiahui.common.action.description.util;

import java.util.List;

import com.thoughtworks.qdox.model.JavaAnnotation;

/**
 * Description <br>
 * Date 2020-01-08 10:37:29<br>
 * 
 * @author XiaHui [onlovexiahui@qq.com]<br>
 * @since 1.0.0
 */

public class JavaAnnotationUtil {

	public static JavaAnnotation getJavaAnnotation(String annotationName, List<JavaAnnotation> jas) {
		if (null != annotationName && null != jas) {
			for (JavaAnnotation ja : jas) {
				if (ja.getType().getFullyQualifiedName().equals(annotationName)) {
					return ja;
				}
			}
		}
		return null;
	}

	public static Object getValue(String annotationName, String property, List<JavaAnnotation> jas) {
		if (null != annotationName && null != property && null != jas) {
			for (JavaAnnotation ja : jas) {
				if (ja.getType().getFullyQualifiedName().equals(annotationName)) {
					return ja.getNamedParameter(property);
				}
			}
		}
		return null;
	}

	public static String getStringValue(String property, JavaAnnotation ja) {
		String text = null;
		Object value = getValue(property, ja);
		if (value instanceof String) {
			text = (String) value;
			text = text.replaceAll("\"", "");
		}
		return text;
	}

	public static Object getValue(String property, JavaAnnotation ja) {
		Object value = null;
		if (null != property && null != ja) {
			value = ja.getNamedParameter(property);
		}
		return value;
	}
}
